<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
${fieldInput}
			<el-form-item>
				<el-button @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button v-auth="'${modelName}:${entityVar}Add'" type="primary" @click="addHandle()">新增</el-button>
			</el-form-item>
		</el-form>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
${fieldTable}
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'${modelName}:${entityVar}Update'" type="primary" link @click="updateHandle(scope.row.id)">修改</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.current"
			:page-size="state.size"
			:total="state.total"
			:page-sizes="state.pageSizes"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗-新增 -->
		<add ref="addRef" @refreshDataList="getDataList"></add>
		<!-- 弹窗-修改 -->
		<update ref="updateRef" @refreshDataList="getDataList"></update>
	</el-card>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { pageHook } from '@/hooks'
import { pageHookOptions } from '@/hooks/interface'
import add from './add.vue'
import update from './update.vue'

const state: pageHookOptions = reactive({
	dataListUrl: '/api/${entityVar}Page',
	queryForm: {
${fieldForm}
	}
})

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle } = pageHook(state)

const addRef = ref()
const addHandle = () => {
	addRef.value.init()
}

const updateRef = ref()
const updateHandle = (id: string) => {
	updateRef.value.init(id)
}
</script>